package com.hyz.util;

import com.hyz.pojo.response.*;
import org.springframework.stereotype.Component;
import pojo.asset.asset.Asset;
import pojo.asset.assetImport.AssetImport;
import pojo.asset.assetMaintenance.AssetMaintenance;
import pojo.asset.assetOutbound.AssetOutbound;
import pojo.asset.assetRetirement.AssetRetirement;
import pojo.asset.assetSecondment.AssetSecondment;

import java.util.ArrayList;
import java.util.List;


/**
 * @author HGD
 * @date 2022/10/6 17:12
 */
@Component
public class Conversion {
    public List<AssetResponse> getAssetResponse(List<Asset> assets) {
        List<AssetResponse> assetResponseList = new ArrayList<>();
        for (Asset asset : assets) {
            assetResponseList.add(AssetResponse.builder()
                    .id(asset.getId().toString())
                    .assetId(asset.getAssetId())
                    .assetName(asset.getAssetName())
                    .supplier(asset.getSupplier())
                    .life(asset.getLife().toString())
                    .status(asset.getStatus().getValue())
                    .classes(asset.getClasses().getValue())
                    .build());
        }
        return assetResponseList;
    }

    public List<AssetImportResponse> getAssetImportResponse(List<AssetImport> assetImports) {
        List<AssetImportResponse> responses = new ArrayList<>();
        for (AssetImport assetImport : assetImports) {
            responses.add(AssetImportResponse.builder()
                    .id(assetImport.getId().toString())
                    .assetId(assetImport.getAssetId().toString())
                    .repositoryId(assetImport.getRepositoryId().toString())
                    .assetManagerId(assetImport.getAssetManagerId().toString())
                    .result(assetImport.getResult().getValue())
                    .createTime(assetImport.getCreateTime().toString())
                    .isComplete(assetImport.getIsComplete().getValue())
                    .build());
        }
        return responses;
    }

    public List<AssetSecondmentResponse> getAssetSecondmentResponse(List<AssetSecondment> assetSecondments) {
        List<AssetSecondmentResponse> responses = new ArrayList<>();
        for (AssetSecondment assetSecondment : assetSecondments) {
            responses.add(AssetSecondmentResponse.builder()
                    .id(assetSecondment.getId().toString())
                    .assetName(assetSecondment.getAssetName())
                    .assetClasses(assetSecondment.getAssetClasses().getValue())
                    .applicantId(assetSecondment.getApplicantId().toString())
                    .secondmentReason(assetSecondment.getSecondmentReason())
                    .status(assetSecondment.getStatus().getValue())
                    .result(assetSecondment.getResult().getValue())
                    .isComplete(assetSecondment.getIsComplete().getValue())
                    .createTime(assetSecondment.getCreateTime().toString())
                    .build());
        }
        return responses;
    }

    public List<AssetOutboundResponse> getAssetOutboundResponse(List<AssetOutbound> assetOutbounds) {
        List<AssetOutboundResponse> responses = new ArrayList<>();
        for (AssetOutbound assetOutbound : assetOutbounds) {
            responses.add(AssetOutboundResponse.builder()
                    .id(assetOutbound.getId().toString())
                    .assetSecondmentId(assetOutbound.getAssetSecondmentId().toString())
                    .assetManagerId(assetOutbound.getAssetManagerId().toString())
                    .assetId(assetOutbound.getAssetId().toString())
                    .repositoryId(assetOutbound.getRepositoryId().toString())
                    .result(assetOutbound.getResult().getValue())
                    .isComplete(assetOutbound.getIsComplete().getValue())
                    .createTime(assetOutbound.getCreateTime().toString())
                    .build());
        }
        return responses;
    }

    public List<AssetMaintenanceResponse> getAssetMaintenanceResponse(List<AssetMaintenance> assetMaintenances) {
        List<AssetMaintenanceResponse> responses = new ArrayList<>();
        for (AssetMaintenance assetMaintenance : assetMaintenances) {
            responses.add(AssetMaintenanceResponse.builder()
                    .id(assetMaintenance.getId().toString())
                    .assetId(assetMaintenance.getAssetId().toString())
                    .applicantId(assetMaintenance.getApplicantId().toString())
                    .result(assetMaintenance.getResult().getValue())
                    .isComplete(assetMaintenance.getIsComplete().getValue())
                    .status(assetMaintenance.getStatus().getValue())
                    .build());
        }
        return responses;
    }

    public List<AssetRetirementResponse> getAssetRetirementResponse(List<AssetRetirement> ars) {
        List<AssetRetirementResponse> responses = new ArrayList<>();
        for (AssetRetirement ar : ars) {
            responses.add(AssetRetirementResponse.builder()
                    .id(ar.getId().toString())
                    .applicantId(ar.getApplicantId().toString())
                    .assetId(ar.getAssetId().toString())
                    .status(ar.getStatus().getValue())
                    .result(ar.getResult().getValue())
                    .isComplete(ar.getIsComplete().getValue())
                    .datetime(ar.getDatetime().toString())
                    .build()
            );
        }
        return responses;
    }
}
